<?php

class Languagemodel extends CI_Model {

	public function getLanguage($language_id) {
		$query = $this->db->query("SELECT * FROM Language WHERE Language_ID = '" . (int) $language_id . "'");

		return $query->row();
	}

	public function getLanguages() {
		//$language_data = $this->cache->get('language');
		$language_data = array();

		$query = $this->db->query("SELECT l.Language_ID,l.Name,l.Code,l.Locale,l.Image,l.Directory,l.Filename,l.Sort_Order,l.Status, lm.MarketFID
        							FROM dbo.Language l JOIN dbo.LanguageMarket lm ON l.Language_ID = lm.LanguageFID AND lm.MarketFID = '". $this->config->item('market') ."'");

		foreach ($query->result() as $result) {
			$language_data[$result->Language_ID] = array(
                'language_id' => $result->Language_ID,
                'name' => $result->Name,
                'code' => $result->Code,
                'locale' => $result->Locale,
                'image' => $result->Image,
                'directory' => $result->Directory,
                'filename' => $result->Filename,
                'sort_order' => $result->Sort_Order,
                'status' => $result->Status
			);
		}

		return $language_data;
	}

	function is_language_using() {
		$is_language_using = $this->session->userdata('language_code');

		//checking login on other pages
		if (!isset($is_language_using) || $is_language_using != true) {
			$is_language_using = "english";
		}

		if ($is_language_using == "en") {
			$is_language_using = "english";
		}

		if ($is_language_using == "id") {
			$is_language_using = "indonesia";
		}

		return $is_language_using;
	}

}

?>